<?php

require_once '../data/ConfigClement.php';
require_once '../data/Banque.php';
require_once '../data/Dossier.php';
require_once '../data/Mails.php';

$serveur = ConfigClement::$serveur;
$nom_base = ConfigClement::$nom_base;
$loginBd = ConfigClement::$loginBd;
$motdepasse = ConfigClement::$motdepasse;


$con = mysql_connect ($serveur,$loginBd,$motdepasse);

if ($con) {

	mysql_select_db($nom_base)or die ('ERREUR '.mysql_error());

	$requete = "SELECT d.* FROM dossier d, comptabilite c WHERE c.date_fin <= TIMESTAMPADD( MONTH , 6, NOW() ) AND d.recall_six_month = 0 AND c.date_fin > '1970-01-01' AND c.id_dossier = d.id";
	$requete_update = "UPDATE  dossier d INNER JOIN comptabilite c ON c.id_dossier = d.id SET d.recall_six_month = 1 WHERE c.date_fin <= TIMESTAMPADD( MONTH , 6, NOW() ) AND d.recall_six_month = 0  AND c.date_fin > '1970-01-01'";
	$resultat = mysql_query ($requete);
	mysql_query ($requete_update);

	
	mysql_close($con);
	
	if (!$resultat) {
		echo "Impossible d'exécuter la requête  dans la base : " . mysql_error();
		exit;
	}

	while ($ligne = mysql_fetch_assoc($resultat)) {
		$dossier = Dossier::getDossierById($ligne['id']);
		$banque = Banque::getBanqueById($dossier->id_banque);
		Mails::sendMailModifDossier($banque, $dossier, 5);
	}

	
	
	
}else {
	echo 'connexion impossible...'.mysql_error();
}






?>